﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using ProgrammersFAQ.BE;
using ProgrammersFAQ.MO;

namespace ProgrammersFAQ.WS
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "PlatformService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select PlatformService.svc or PlatformService.svc.cs at the Solution Explorer and start debugging.
    public class PlatformService : IPlatformService
    {
        public void DoWork()
        {
        }

        public PlatformMO[] getPlatformList()
        {
            using (ProgrammersFAQEntities entities = new ProgrammersFAQEntities())
            {
                Platform[] result = (from a in entities.Platforms
                                     select a).ToArray();
                PlatformMO[] resultValue = null;
                if (result != null && result.Count() > 0)
                {
                    resultValue = new PlatformMO[result.Count()];
                    for (int i = 0; i < result.Count(); i++)
                    {
                        PlatformMO model = new PlatformMO();
                        model.id = result[i].id;
                        model.platform = result[i].platform1;
                        resultValue[i] = model;
                    }

                }

                return resultValue;
            }
        }

        public string getPlatformComboList()
        {
            using (ProgrammersFAQEntities entities = new ProgrammersFAQEntities())
            {
                Platform[] platformList = (from a in entities.Platforms
                                           select a).ToArray();

                string comboStr = "";

                foreach (Platform platform in platformList)
                {
                    comboStr += "<option value=\"" + platform.id + "\">" + platform.platform1 + "</option>";
                }

                return comboStr;
            }
        }
    }
}

